﻿using GraphProcessor;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.CancelNavigation, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_CancelNavigation : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.CancelNavigation;

        public override string name => LevelEditorConst.CancelNavigation;
        [Output("目标", false)] public EditorLevelServiceTargetSetter tagOrMcid;
        [InspectorName("是否触发寻路结束的服务")] public bool isTriggerService;
        [InspectorName("是否瞬移到终点")] public bool isTeleportToFinalDestination;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_CancelNavigation()
            {
                isTriggerService = this.isTriggerService,
                isTeleportToFinalDestination = this.isTeleportToFinalDestination
            };
            tagOrMcid = new EditorLevelServiceTargetSetter(x => rConfig.tagOrMcid = x);
            return rConfig;
        }

        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_CancelNavigation rNode)
            {
                this.isTriggerService = rNode.isTriggerService;
                this.isTeleportToFinalDestination = rNode.isTeleportToFinalDestination;
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_CancelNavigation rConfig)
            {
                this.SyncTarget(rConfig.tagOrMcid, nameof(tagOrMcid));
            }
        }
    }
}